////////////////////////////////////////////page_parkIndex////////////////////////////////
$(document).on("pageInit", "#page_parkIndex", function(e, pageId, $page) {
	             //sessionStorage.parking_ygsy=1
	            //清空parkIndexFligth查询信息////////////////////////////////////

	            $('.flightInfo-box-cx-list').empty()
	            $('.flightNum').val('')
	            $('.flightDate').val('')
	            $('.flightInfo-box-zdy-list-box').css('display','none')

	             //清空parkIndexFligth查询信息///////////////////////////////
                my.givetitle('泊车');
                $('.popup-overlay').remove()

                my.getlogintiaozhuan();
	            if(my.getCookie('token')&&my.getCookie('id')){
	            var key=my.get_key(my.getCookie('token'))
	            $('.bar-tab').show()
         		$('.bannerDown-parkIndex').off('click').on('click',function(){
         			$('.banner-parkIndex').show();
         			$(this).hide()
         		})
         		$('.bannerUp-parkIndex').off('click').on('click',function(){
         			$('.banner-parkIndex').hide();
         			$('.bannerDown-parkIndex').show().css('display','block')
         		})
         		//选择时间
                    var now=new Date();
                    var afteryear  = new Date();
                    var months =  now.getMonth()+1;
                    var nowdateone =  now.getDate()+1;
                     afteryear.setFullYear(afteryear.getFullYear()+1);
                    var aftermonthsone =  afteryear.getMonth()+1;
                    var formatNumber = function (n) {
                        return n < 10 ? "0" + n : n;
                    };

                    var minutesss = function (n) {
                        if(n>=0 && n<=15){
                            return '00';
                        }
                        if(n>15 && n<=30){
                            return '30';
                        }
                        if(n>31 && n<=45){
                            return '45';
                        }
                        if(n>45 && n<=60){
                            return '45';
                        }
                    };
                    $(".start_parkIndex_start").datetimePickerCustom({

                        toolbarTemplate: '<header class="bar bar-nav">\
        <button class="button button-link pull-left script_swapend" onclick="$(\'.start_parkIndex_start\').datetimePickerCustom(\'close\');$(\'.end_parkIndex_end\').datetimePickerCustom(\'open\');">结束时间</button>\
  <button class="button button-link pull-right close-picker">确定</button>\
  <h1 class="title">请设置开始时间</h1> </header>',

                        customValue:now.getFullYear()+"-"+formatNumber(months)+"-"+formatNumber(now.getDate())+" "+formatNumber(now.getHours())+":"+minutesss(now.getMinutes())+":00",//指定控件中的当前时间日期,需要是示例所示标准格式
                        customMinuteInterval:4,//指定分钟的间隔方式，此处整型指定分钟间隔的分母，如指定4，则为1/4，即分钟选择会变成00,15,30,45，该值不能为0
                        hideMinute:false,//是否隐藏分钟,隐藏分钟则控件值为yyyy-MM-dd hh
                        hideHour:false,//是否隐藏小时,隐藏小时则控件值为yyyy-MM-dd
                        minDate:now.getFullYear()+"-"+formatNumber(months)+"-"+formatNumber(now.getDate())+" "+formatNumber(now.getHours())+":"+minutesss(now.getMinutes())+":00",//指定最小日期时间
                        maxDate:afteryear.getFullYear()+"-"+formatNumber(aftermonthsone)+"-"+formatNumber(afteryear.getDate())+" "+formatNumber(afteryear.getHours())+":"+minutesss(afteryear.getMinutes())+":00",//指定最大日期时间
                        hourLimit:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]//指定小时限制，只有数组中出现的小时才能被选择

                    });
                    $(".end_parkIndex_end").datetimePickerCustom({
                        toolbarTemplate: '<header class="bar bar-nav">\
        <button class="button button-link pull-left script_swapend" onclick="$(\'.end_parkIndex_end\').datetimePickerCustom(\'close\');$(\'.start_parkIndex_start\').datetimePickerCustom(\'open\');">开始时间</button>\
  <button class="button button-link pull-right close-picker">确定</button>\
  <h1 class="title">设置结束时间</h1></header>',
                        customValue:now.getFullYear()+"-"+months+"-"+nowdateone+" "+now.getHours()+":"+minutesss(now.getMinutes())+":00",//指定控件中的当前时间日期,需要是示例所示标准格式
                        customMinuteInterval:4,//指定分钟的间隔方式，此处整型指定分钟间隔的分母，如指定4，则为1/4，即分钟选择会变成00,15,30,45，该值不能为0
                        hideMinute:false,//是否隐藏分钟,隐藏分钟则控件值为yyyy-MM-dd hh
                        hideHour:false,//是否隐藏小时,隐藏小时则控件值为yyyy-MM-dd
                        minDate:now.getFullYear()+"-"+months+"-"+nowdateone+" "+now.getHours()+":"+minutesss(now.getMinutes())+":00",//指定最小日期时间
                        maxDate:afteryear.getFullYear()+"-"+aftermonthsone+"-"+afteryear.getDate()+" "+afteryear.getHours()+":"+minutesss(afteryear.getMinutes())+":00",//指定最大日期时间
                        hourLimit:[0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,21,22,23]//指定小时限制，只有数组中出现的小时才能被选择

                    });

                     // $('.start_parkIndex_start,.end_parkIndex_end').val('')//清空默认时间
                      $('.start_parkIndex_start,.end_parkIndex_end').change(function(){
                      	if($('.start_parkIndex_start').val()!=''&&$('.end-parkIndex').val()!=''){
                      		var start= $('.start_parkIndex_start').val().replace(/-/g, "/")
                      		var end= $('.end_parkIndex_end').val().replace(/-/g, "/")

                      		end=Date.parse(end)
                      		start=Date.parse(start)
                            $('.time-ts').html(start+'<br>'+end)
                      		if(end>start)//结束大于开始
                      		{
                      			$('.time-parkIndex span').eq(2).text((end-start)/3600000)
                                $('.time-ts').empty()
                      		}else{
                      			$('.time-ts').text('结束时间必须大于开始时间!').css('color','red')
                      		}
                      	}
                      })
                      //协议
                      $('.xy-parkIndex').off('click').on('click',function(){
      				    $.popup('.popup-parkIndex');
      				    $('.xy-parkIndex span').css('background-color','#3C3C3C').attr('name','1')
      				    my.countSubmit('15','.xy-count')
      			      })
      			      $('.xy-no').off('click').on('click',function(){
                        	$('.xy-parkIndex span').css('background-color','#fff').attr('name','0')
      				        clearTimeout(t)
      			         })
                      $('.xy-ok').off('click').on('click',function(){
                        	clearTimeout(t)
                        	$('.xy-parkIndex span').css('background-color','#3C3C3C').attr('name','1')
                      })
                      $('.flightInfo-parkIndex-box').off('click').on('click',function(e){

                      		 $.router.load('#page_parkIndexFlight',true)
                      		 $('.flightInfo-ok').removeClass('active_btn').off('click')

                      })
                      $('.submit-parkIndex').off().on("click",function(){
                      	 if($('[name=parking_starttime]').val()=='开始时间'||$('[name=parking_endtime]').val()=='结束时间'||$('[name=store_id]').val()==''||$('[name=park_models_id]').val()=='')
                      	 {
                      	 	$.alert('请填写完整');
                      	 	return
                      	 }
                      	 if($('.xy-parkIndex span').attr('name')=='0'){
                      	 	$.alert('请阅读车去车来泊车协议')
                      	 }else{
                      	 	//ajax开始
                      	 	$.showPreloader()
      				        var info={
      						   'parking_starttime':$('[name=parking_starttime]').val()+":00",
      						   'parking_endtime':$('[name=parking_endtime]').val()+":00",
      						   'store_id':$('[name=store_id]').val(),
      						   'models_id':$('[name=park_models_id]').val(),
      					     }
      				         console.log(info)
    					     info=JSON.stringify(info)
                             info=my.cryptoASEencrypt(info,key).toString()

      				        $.ajax({
      						   type:"post",
      					     	url:api.calculateparkingprice,
      						data:{
      							'api_value':info
      						},
      						async:true,
      						error:function(){
      							$.hidePreloader()
      							$.toast("提交失败，请重试");
      						},
      						success:function(data){
      							$.hidePreloader()
      							if(data.match("err_code")!=null){
      								switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}

      							}else{
      								    data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    console.log(data)
      								    sessionStorage.parking_starttime=$('[name=parking_starttime]').val()+":00",
      								    sessionStorage.parking_endtime=$('[name=parking_endtime]').val()+":00",
      								    sessionStorage.park_total_time=data.total_time
      								    sessionStorage.park_total_price=data.total_price
      								    sessionStorage.parking_unit=data.parking_unit
      								    sessionStorage.parking_unit_price=data.parking_unit_price
      								    sessionStorage.official_price=data.official_price
      								    sessionStorage.is_allowrent=data.is_allowrent //是否允许分享
      								    sessionStorage.parking_ygsy=data.plan_income //预估收益
      							       // $.router.loadPage("parkChoosePayment.html");
                                    $.router.load(parkChoosePaymentUrl,true);
      							}
      						},
      				        });
      				        //ajax结束
                      	 }
                      })
                      $('.select-carInfo-parkIndex').off('click').on('click',function(){
                      	$.router.load("#page_parkIndexGetCar");
                      })

                      }else{
	            	$('.page').off('click').on('click',function(){
	            		my.setCookie('token','',-1)
                        my.setCookie('id','',-1)
                        my.setCookie('phone','',-1)
	                    $.alert("请先登录",function(){
                              // window.location.href=config.domain+'sui_BMW/login.html';
                            $.router.load(loginUrl,true);
                        });
	            	})
	            }
});
$(document).on("pageInit", "#page_noLoginparkIndex", function(e, pageId, $page) {
    my.getlogintiaozhuan();
    $(".nologinparkindex").on("click",function(){
        if(my.getCookie('token') && my.getCookie('id')){
            $.router.load(config.domain+'/h5cargo/index/parkindex.htm#page_parkIndex',true);
        }else{
            $.router.load(config.domain+loginUrl+'?return_url=/h5cargo/index/parkindex.htm#page_parkIndex',true);
        }

    });
     var mySwiper = new Swiper('.swiper-container',{
                                                       pagination : '.swiper-pagination',
                                                       autoplay : 4000,
                 })

});